package Project;

import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
/**
 * This class contains all the graphics of Title screen.
 * 
 * @author	Brian Wetherbee
 * 			Ryan McNamara
 * 			Zeng Yang
 *
 */
public class TitleScreen extends Menu {
	/*@ public invariant Main.UI = this; @*/
	
	/**
     * Creates new form TitleScreen
     */
    public TitleScreen() {
        super(3);
        initComponents();

        
    }
    
    public void paint(Graphics g){
    	super.paint(g);
    	g.setColor(Color.BLACK);
    	g.fillRect(0, 0, Constants.width, Constants.height);
    	g.setColor(Color.WHITE);
    	g.setFont(new java.awt.Font("DialogInput",1,50));
    	FontMetrics f = g.getFontMetrics(new java.awt.Font("DialogInput",1,50));
    	int stringX = (int)(f.stringWidth("2012 - A Space Adventure"));
    	int stringY = (int)(f.getHeight());

    	int x = Constants.width / 2 - (stringX/2);
    	int y = (int) (Constants.height / 5 + (stringY)/2);
    	g.drawString("2012 - A Space Adventure",x, y);
    	
    	
    	//start game
    	g.setFont(new java.awt.Font("DialogInput",1,24));
    	f = g.getFontMetrics(new java.awt.Font("DialogInput",1,24));
    	stringX = (int)(f.stringWidth("Start Game"));
    	stringY = (int)(f.getHeight());
    	x = Constants.width / 2 - (stringX/2);
    	y = Constants.height- 400 + (stringY)/2;
    	g.drawString("Start Game",x, y);
    	if(getOption() == 0){
    		g.fillRect(x, y, stringX, 5);
    	}
		// load game

    	stringX = (int) (f.stringWidth("Load Game"));
		x = Constants.width / 2 - (stringX / 2);
		y = Constants.height - 300 + (stringY) / 2;
		g.drawString("Load Game", x, y);
		if (getOption() == 1) {
			g.fillRect(x, y, stringX, 5);
		}
		// exit game
		stringX = (int) (f.stringWidth("Exit Game"));
    	x=Constants.width / 2 - (stringX/2);
    	y=Constants.height- 200 + (stringY)/2;
    	g.drawString("Exit Game",x, y);
    	if(getOption() == 2){
    		g.fillRect(x, y, stringX, 5);
    	}
    }
    
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
        addKeyListener(this);
        addMouseListener(this);
        repaint();
    }// </editor-fold>     
    
    
/*
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
       
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
    	repaint();

        title = new javax.swing.JLabel();
        optionStart = new javax.swing.JLabel();
        optionExit = new javax.swing.JLabel();
        optionLoad = new javax.swing.JLabel();

        setBackground(new java.awt.Color(0, 0, 0));
        this.setSize((int)Main.getActualComponentSize().getX(), (int)Main.getActualComponentSize().getY());
        addKeyListener(this);


        int size = (int)Math.min(Main.internalToActualX(24),Main.internalToActualY(24));
        
        title.setFont(new java.awt.Font("DialogInput", 1, size)); // NOI18N
        title.setForeground(new java.awt.Color(255, 255, 255));
        title.setText("2012 - A Space Adventure");

        optionStart.setFont(new java.awt.Font("DialogInput", 1, 18)); // NOI18N
        optionStart.setForeground(new java.awt.Color(255, 255, 255));
        optionStart.setText("Start Game");
        optionStart.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255), 2));

        optionExit.setFont(new java.awt.Font("DialogInput", 1, 18)); // NOI18N
        optionExit.setForeground(new java.awt.Color(255, 255, 255));
        optionExit.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        optionExit.setText("Exit Game");
        optionExit.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));

        optionLoad.setFont(new java.awt.Font("DialogInput", 1, 18)); // NOI18N
        optionLoad.setForeground(new java.awt.Color(255, 255, 255));
        optionLoad.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        optionLoad.setText("Load Game");
        optionLoad.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(153, Short.MAX_VALUE)
                .addComponent(title)
                .addGap(151, 151, 151))
            .addGroup(layout.createSequentialGroup()
                .addGap(260, 260, 260)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(optionStart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(optionLoad, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(optionExit, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addComponent(title)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 206, Short.MAX_VALUE)
                .addComponent(optionStart)
                .addGap(18, 18, 18)
                .addComponent(optionLoad)
                .addGap(18, 18, 18)
                .addComponent(optionExit)
                .addGap(82, 82, 82))
        );

        optionStart.getAccessibleContext().setAccessibleParent(this);
    }// </editor-fold>                        */

    private void formKeyPressed(java.awt.event.KeyEvent evt) {                                
       
        
    }                               
    
    private void drawPanels() {
        if(getOption() == 0)
        {
            optionStart.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.WHITE, 2));
            optionLoad.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.BLACK, 2));
            optionExit.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.BLACK, 2));
        }
        
        if(getOption() == 1)
        {
            optionStart.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.BLACK, 2));
            optionLoad.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.WHITE, 2));
            optionExit.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.BLACK, 2));
        }
        
        if(getOption() == 2)
        {
            optionStart.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.BLACK, 2));
            optionLoad.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.BLACK, 2));
            optionExit.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.WHITE, 2));
        }
    }
    
    public void passEvent(java.awt.event.KeyEvent evt) {
        formKeyPressed(evt);
    }
    
    @Override
    public void select() {
        if(getOption() == 0) {
        	//create a new game
        	SaveFile.CreateNewFile();
            Main.setCurrentUI(Constants.StoryNum);
        }
        if(getOption() == 1) {
        	//create a new game
            Main.setCurrentUI(Constants.TitleScreenLoadGame);
        }
            
        if(getOption() == 2) {
            System.exit(0);
        }
    }
    
    // Variables declaration - do not modify                     
    private javax.swing.JLabel optionExit;
    private javax.swing.JLabel optionLoad;
    private javax.swing.JLabel optionStart;
    private javax.swing.JLabel title;
    // End of variables declaration
	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyPressed(KeyEvent e) {
		 if(e.getKeyCode() == Constants.controlDown)
	        {
	            increaseHighlight();
	        }
	        
	        if(e.getKeyCode() == Constants.controlUp)
	        {
	            decreaseHighlight();
	        }
	        
	        if(e.getKeyCode() == Constants.controlConfirm)
	        {
	            select();
	        }
	        if(e.getKeyCode() == Constants.controlToggleFullScreen){
	        	Main.toggleFullScreen();
	        }
	        repaint();
		
	}

	@Override
	public void keyReleased(KeyEvent e) {
	}
	@Override
	public void componentResized(ComponentEvent e){
		
	}
	
}
